package com.ccx.library.export;

import com.alibaba.excel.EasyExcel;
import com.ccx.library.module.user.entity.User;
import com.ccx.library.util.SnowflakeUtil;


import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 写入excel
 */
public class ExportExcel<T> {

    public static <T> void Export(Class cls, String sheet, Supplier<List<T>> supplier) {
        try {
            // 雪花算法
            String fileName = UserDir() + SnowflakeUtil.nextValue() + ".xlsx";
            EasyExcel.write(fileName, cls)
                    .sheet(sheet).doWrite(() -> supplier.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private final static String SUBFIX = "\\src\\main\\resources\\file\\export\\";

    protected static String UserDir() {
        return System.getProperty("user.dir") + SUBFIX;
    }

}
